/*
 * 
 * Copyright 2011 visual-analysis-of-cancer.
 * This file is part of visual-analysis-of-cancer.
 * 
 * visual-analysis-of-cancer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * visual-analysis-of-cancer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with kOSMik.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * visual-analysis-of-cancer:
 * An tool to analye the WHO and GLOBOCAN cancer data.
 * http://code.google.com/p/visual-analysis-of-cancer/
 * 
 * 
 * 
 * Authors: Erik Sniegula, Johannes Dahlke
 * 
 * Module:  Programming in Processing for Visual Analytics
 * Group:   20
 * 
 * Created: Aug. 2011
 * Version: 1.0
 *
 */
 




package de.fuberlin.processing.who.cancer.gui;

import java.util.Observable;
import java.util.Observer;

import processing.core.PApplet;
import processing.core.PImage;
import controlP5.ControlP5;
import controlP5.Controller;
import controlP5.Tab;
import de.fuberlin.processing.who.cancer.data.DBException;
import de.fuberlin.processing.who.cancer.data.Database;
import de.fuberlin.processing.who.cancer.data.DatabaseConnector;
import de.fuberlin.processing.who.cancer.interaction.LocationBroadcaster;
import de.fuberlin.processing.who.cancer.interaction.LocationModifier;
import de.fuberlin.processing.who.cancer.run.CancerSketch;


public class WorldGraph extends Controller implements Observer {

	public static final int NUM_GRAPH_WIDTH = Scatterplot.NUM_PLOT_WIDTH;
	public static final int NUM_GRAPH_HEIGHT = CancerSketch.NUM_SKETCH_HEIGHT
			- Scatterplot.NUM_PLOT_HEIGHT - 5 * CancerSketch.NUM_SKETCH_PADDING;
	private int left;
	private int top;
	private LocationModifier locationModifier;
	private DatabaseConnector db;


	public WorldGraph( ControlP5 theControlP5,
			String theName, int theX, int theY) {
		super( theControlP5, (Tab) ( theControlP5.getTab( "default")), theName,
				theX, theY, NUM_GRAPH_WIDTH, NUM_GRAPH_HEIGHT);
		this.locationModifier = LocationBroadcaster.get();
		this.locationModifier.addObserver( this);
		this.left = theX;
		this.top = theY;

		connectToDatabase();
		this.captionLabel().setVisible( false);
		loadMockup();
	}


	private void connectToDatabase() {
		try {
			db = Database.get();
		} catch ( DBException e) {
			e.printStackTrace();
		}
	}

	// remove loadMockup() later
	private PImage mockupImage;


	private void loadMockup() {
		mockupImage = ControlP5.papplet
				.loadImage( "../data/world_graph_mockup.png");
	}


	// overwrite the draw method for the controller's visual representation.
	public void draw( PApplet theApplet) {
		PApplet p = theApplet;
		p.pushStyle();
		p.image( mockupImage, this.left, this.top, this.width, this.height);
		p.popStyle();
	}


	@Override
	public Controller setValue( float theValue) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public void update( Observable o, Object arg) {
		// TODO Auto-generated method stub

	}

}
